﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CoolCode;
using CoolCode.Linq;
using XNoteBook.Services;
using XNoteBook.Models;
using XNoteBook.Entities;
using XNoteBook.UI.Models;

namespace XNoteBook.UI.Controllers
{
	public class SampleController : CoolCode.Web.Mvc.ControllerBase
	{
		private IPostService _PostService;
		public IPostService PostService
		{
			get
			{
				if (_PostService == null)
				{
					_PostService = Digger.Dig<IPostService>();
				}
				return _PostService;
			}
		}

		public ActionResult Index()
		{
			return View();
		}
 
		public ActionResult Top10Layout()
        {
			HomeIndexModel model = new HomeIndexModel();
			model.TopTenPosts.Add(this.PostService.ListTop10PostsByFrequency());
			model.TopTenPosts.Add(this.PostService.ListTop10PostsByViews());
			model.TopTenPosts.Add(this.PostService.ListTop10PostsByDate());

			return View(model);
        }

		public ActionResult ItemList(int? page)
		{
			var model = SampleData.AsQueryable().AsPageable(new PageParam(page.GetValueOrDefault()));//.Paging(new PageParam(page.GetValueOrDefault()));
			return PartialView(model);  
		}

		public static readonly List<FooModel> SampleData = new List<FooModel>
		{
			 new FooModel{ID =Guid.NewGuid(), Name ="Bruce Lee", Age = 100 , CreateTime =new DateTime(2000,1,1)  },
			 new FooModel{ID =Guid.NewGuid(), Name ="Tony Luk", Age = 40 , CreateTime =new DateTime(2240,12,11)  },
			 new FooModel{ID =Guid.NewGuid(), Name ="John Ye", Age = 23 , CreateTime =new DateTime(2078,4,1)  },
			 new FooModel{ID =Guid.NewGuid(), Name ="Kitty", Age = 34 , CreateTime =new DateTime(1900,1,13)  },
			 new FooModel{ID =Guid.NewGuid(), Name ="Eric Chen", Age = 340 , CreateTime =new DateTime(2010,11,1)  },
			 new FooModel{ID =Guid.NewGuid(), Name ="Terry Lee", Age = 50 , CreateTime =new DateTime(2000,12,12)  },
			 new FooModel{ID =Guid.NewGuid(), Name ="Jeff Zhao", Age = 7 , CreateTime =new DateTime(2000,12,11)  },
			 new FooModel{ID =Guid.NewGuid(), Name ="Huanzhu", Age = 16 , CreateTime =new DateTime(2000,11,21)  },
			 new FooModel{ID =Guid.NewGuid(), Name ="Bill Gate", Age = 188 , CreateTime =new DateTime(2000,5,1)  },
			 new FooModel{ID =Guid.NewGuid(), Name ="Apple Pie", Age = 50 , CreateTime =new DateTime(2000,1,7)  },
			 new FooModel{ID =Guid.NewGuid(), Name ="Petter", Age = 70 , CreateTime =new DateTime(2000,1,8)  },
			 new FooModel{ID =Guid.NewGuid(), Name ="HooPoo Lift", Age = 20 , CreateTime =new DateTime(2000,9,1)  },
			 new FooModel{ID =Guid.NewGuid(), Name ="Jack", Age = 10 , CreateTime =new DateTime(2000,11,11)  },
			 new FooModel{ID =Guid.NewGuid(), Name ="Rose", Age = 5 , CreateTime =new DateTime(2000,5,5)  },
			 new FooModel{ID =Guid.NewGuid(), Name ="Wood", Age = 45 , CreateTime =new DateTime(2000,6,2)  },
			 new FooModel{ID =Guid.NewGuid(), Name ="YaoMing" , Age= 27 , CreateTime =new DateTime(2000,6,17)  },
			 new FooModel{ID =Guid.NewGuid(), Name ="Yi Jian Luan", Age = 30 , CreateTime =new DateTime(2000,9,20)  },
			 new FooModel{ID =Guid.NewGuid(), Name ="Tom", Age = 70 , CreateTime =new DateTime(2000,1,31)  },
			 new FooModel{ID =Guid.NewGuid(), Name ="Jerry", Age = 80 , CreateTime =new DateTime(2000,4,6)  },
		};

		public ActionResult DropDownList()
		{
			return View();
		}
		
		public ActionResult TreeDropDownList()
		{
			return View();
		}

		public ActionResult KillEvent()
		{
			return View();
		}
	}

	public class FooModel
	{
		public Guid ID { get; set; }
		public string Name { get; set; }
		public int Age { get; set; }
		public DateTime CreateTime { get; set; }
	}
}
